<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>percentiles_bucket 聚合 | ElasticSearch 7.7 权威指南中文版</title>
	<meta name="keywords" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <meta name="description" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
	<script>
	var _link = 'search-aggregations-pipeline-percentiles-bucket-aggregation.html';
    </script>
</head>
<body>
<div class="main-container">
    <section id="content">
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.7/search-aggregations-pipeline-percentiles-bucket-aggregation.html" rel="nofollow" target="_blank">https://www.elastic.co/guide/en/elasticsearch/reference/7.7/search-aggregations-pipeline-percentiles-bucket-aggregation.html</a>, 原文档版权归 www.elastic.co 所有<br/>本地英文版地址: <a href="../en/search-aggregations-pipeline-percentiles-bucket-aggregation.html" rel="nofollow" target="_blank">../en/search-aggregations-pipeline-percentiles-bucket-aggregation.html</a></div>
                        <!-- start body -->
                  <div class="page_header">
<strong>重要</strong>: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="nofollow">当前版本文档</a>。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch 权威指南 [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="search-aggregations.html">聚合</a></span>
»
<span class="breadcrumb-link"><a href="search-aggregations-pipeline.html">管道聚合</span>
»
<span class="breadcrumb-node">percentiles_bucket 聚合</span>
</div>
<div class="navheader">
<span class="prev">
<a href="search-aggregations-pipeline-derivative-aggregation.html">« derivative 聚合</a>
</span>
<span class="next">
<a href="search-aggregations-pipeline-movavg-aggregation.html">moving_avg 聚合 »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="search-aggregations-pipeline-percentiles-bucket-aggregation"></a>百分位数桶(percentiles_bucket)聚合
</h2>
</div></div></div>
<p>
一种同级管道聚合，用于计算同级聚合中指定度量的所有桶的百分位数。

指定的度量必须是数字，并且同级聚合必须是多桶聚合。
</p>
<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="_syntax_11"></a>语法
</h3>
</div></div></div>
<p>一个单独的<code class="literal">percentiles_bucket</code>看起来像这样：</p>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">{
    "percentiles_bucket": {
        "buckets_path": "the_sum"
    }
}</pre>
</div>
<div class="table">
<a id="percentiles-bucket-params"></a>
<p class="title"><strong>表 17. <code class="literal">percentiles_bucket</code>参数</strong></p>
<div class="table-contents">
<table border="1" cellpadding="4px" summary="percentiles_bucket Parameters">
<colgroup>
<col class="col_1">
<col class="col_2">
<col class="col_3">
<col class="col_4">
</colgroup>
<thead>
<tr>
<th align="left" valign="top">参数名称</th>
<th align="left" valign="top">描述</th>
<th align="left" valign="top">是否必需</th>
<th align="left" valign="top">默认值</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left" valign="top"><p><code class="literal">buckets_path</code></p></td>
<td align="left" valign="top"><p>
我们希望找到百分位数的桶的路径(更多详情请参考 <a class="xref" href="search-aggregations-pipeline.html#buckets-path-syntax" title="buckets_path语法" rel="nofollow"><code class="literal">buckets_path</code>语法</a>)
 </p></td>
<td align="left" valign="top"><p>必需</p></td>
<td align="left" valign="top"><p></p></td>
</tr>
<tr>
<td align="left" valign="top"><p><code class="literal">gap_policy</code></p></td>
<td align="left" valign="top"><p>
在数据中发现间隙时应用的策略(更多详情请参考<a class="xref" href="search-aggregations-pipeline.html#gap-policy" title="处理数据中的间隙">处理数据中的间隙</a>)
</p></td>
<td align="left" valign="top"><p>可选</p></td>
<td align="left" valign="top"><p><code class="literal">skip</code></p></td>
</tr>
<tr>
<td align="left" valign="top"><p><code class="literal">format</code></p></td>
<td align="left" valign="top"><p>应用于此聚合的输出值的格式</p></td>
<td align="left" valign="top"><p>可选</p></td>
<td align="left" valign="top"><p><code class="literal">null</code></p></td>
</tr>
<tr>
<td align="left" valign="top"><p><code class="literal">percents</code></p></td>
<td align="left" valign="top"><p>要计算的百分位数值的列表</p></td>
<td align="left" valign="top"><p>可选</p></td>
<td align="left" valign="top"><p><code class="literal">[ 1, 5, 25, 50, 75, 95, 99 ]</code></p></td>
</tr>
<tr>
<td align="left" valign="top"><p><code class="literal">keyed</code></p></td>
<td align="left" valign="top"><p>一个标志, 是否将范围作为哈希而不是键值对数组返回</p></td>
<td align="left" valign="top"><p>可选</p></td>
<td align="left" valign="top"><p><code class="literal">true</code></p></td>
</tr>
</tbody>
</table>
</div>
</div>
<p>
下面这个代码片段计算每月总销售额(<code class="literal">sales</code>)的百分位数：
</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST /sales/_search
{
    "size": 0,
    "aggs" : {
        "sales_per_month" : {
            "date_histogram" : {
                "field" : "date",
                "calendar_interval" : "month"
            },
            "aggs": {
                "sales": {
                    "sum": {
                        "field": "price"
                    }
                }
            }
        },
        "percentiles_monthly_sales": {
            "percentiles_bucket": {
                "buckets_path": "sales_per_month&gt;sales", <a id="CO271-1"></a><i class="conum" data-value="1"></i>
                "percents": [ 25.0, 50.0, 75.0 ] <a id="CO271-2"></a><i class="conum" data-value="2"></i>
            }
        }
    }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/563.console"></div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO271-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>
<code class="literal">buckets_path</code>指示这个 percentiles_bucket 聚合，我们要为<code class="literal">sales_per_month</code>日期直方图中的<code class="literal">sales</code>聚合计算百分位数。
</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO271-2"><i class="conum" data-value="2"></i></a></p>
</td>
<td align="left" valign="top">
<p>
<code class="literal">percents</code>指定我们希望计算哪些百分位数，在本例中，是第25、50和75个百分位。
</p>
</td>
</tr>
</table>
</div>
<p>响应可能像下面这样：</p>
<div class="pre_wrapper lang-console-result">
<pre class="programlisting prettyprint lang-console-result">{
   "took": 11,
   "timed_out": false,
   "_shards": ...,
   "hits": ...,
   "aggregations": {
      "sales_per_month": {
         "buckets": [
            {
               "key_as_string": "2015/01/01 00:00:00",
               "key": 1420070400000,
               "doc_count": 3,
               "sales": {
                  "value": 550.0
               }
            },
            {
               "key_as_string": "2015/02/01 00:00:00",
               "key": 1422748800000,
               "doc_count": 2,
               "sales": {
                  "value": 60.0
               }
            },
            {
               "key_as_string": "2015/03/01 00:00:00",
               "key": 1425168000000,
               "doc_count": 2,
               "sales": {
                  "value": 375.0
               }
            }
         ]
      },
      "percentiles_monthly_sales": {
        "values" : {
            "25.0": 375.0,
            "50.0": 375.0,
            "75.0": 550.0
         }
      }
   }
}</pre>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="_percentiles_bucket_implementation"></a>percentiles_bucket的实现
</h3>
</div></div></div>
<p>
百分位桶返回不大于所请求的百分位的最接近的输入数据点；它不会在数据点之间进行插值。
</p>
<p>
百分位数是精确计算的，不是近似值(不同于百分位数度量<span class="remark">percentiles metric</span>)。

这意味着在丢弃数据之前，该实现在内存中维护一个数据的排序列表来计算百分位数。

如果你试图在一个<code class="literal">percentiles_bucket</code>中计算数百万个数据点的百分位数，则可能会遇到内存压力问题。
</p>
</div>

</div>
<div class="navfooter">
<span class="prev">
<a href="search-aggregations-pipeline-derivative-aggregation.html">« derivative 聚合</a>
</span>
<span class="next">
<a href="search-aggregations-pipeline-movavg-aggregation.html">moving_avg 聚合 »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>